package com.rd.student.jike.class1.sunhao.day11;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class TextExecutor {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,20,
                1l, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                new ThreadPoolExecutor.DiscardPolicy());
//        for (int i = 0;i<5;i++){
//            MyRunnable runnable  = new MyRunnable();
//            executor.execute(runnable);
//        }
//        executor.shutdown();
        List<Future<String>> futureList = new ArrayList<>();
        MyCallaable callabke = new MyCallaable();
        for (int i=0;i<12;i++){
            Future<String> future=executor.submit(callabke);
            futureList.add(future);
        }
        for (Future<String> future :futureList){
            try{
                String result= future.get();
                System.out.println(result);
            }catch(InterruptedException| ExecutionException e){
                e.printStackTrace();
            }
        }
        executor.shutdown();
    }
}
